﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entities;
using Utility;
using BUS;

public partial class Administrator_ds_voucher : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        Literal1.Text = "Danh sách Voucher";
        pager.PageSize = 15;
        Criteria c = new Criteria();
        int total = 0;
        
        Tbl_Voucher_Collection vcCollection =
               Tbl_Voucher_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
               Tbl_Voucher_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = vcCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_Voucher_Entities vc = (Tbl_Voucher_Entities)e.Item.DataItem;
            Tbl_DonHang_Entities dh = Tbl_DonHang_BUS.GetByID(vc.DonHang);
            Tbl_CTDH_Entities ctdh = Tbl_CTDH_BUS.GetByIDDH(dh.STT);
            Tbl_SanPham_Entities sp = Tbl_SanPham_BUS.GetByID(ctdh.SanPham);

            Literal lit_serial = (Literal)e.Item.FindControl("lit_serial");
            HyperLink hyp_madh = (HyperLink)e.Item.FindControl("hyp_madh");
            Literal lit_stt = (Literal)e.Item.FindControl("lit_stt");
            CheckBox cb_used = (CheckBox)e.Item.FindControl("cb_used");

            lit_stt.Text = vc.STT.ToString();

            if (vc.Used == true)
            {
                cb_used.Checked = true;
            }
            else
            {
                cb_used.Checked = false;
            }

            hyp_madh.NavigateUrl = "~/Administrator/dathang_chitiet.aspx?id=" + dh.STT.ToString();
            hyp_madh.Text = dh.MaDH.ToString();
            lit_serial.Text = vc.Serial;
        }
    }
    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        load_data();
    }
}
